﻿using System;
using System.Xml.Linq;
using Core;
using Xunit;

namespace UnitTest
{
    public class CategoryUnitTest : TestingBase
    {
        [Fact]
        public void ParseCategory_ExpectAllCategoriesLoaded()
        {
            Category category = this.GetParsedCategory();

            Assert.Equal(7, category.CategoryItems.Count);
        }

        [Fact]
        public void CategoryItems_ExcpectCategoryItemsLoaded()
        {
            Category category = this.GetParsedCategory();

            CategoryItem item0 = category.CategoryItems[0];
            Assert.True(item0.Id != Guid.Empty);
            Assert.Equal("finance", item0.WpNiceName);
            Assert.Equal("finance", item0.Name);
            Assert.Equal("finance", item0.Description);

            CategoryItem item3 = category.CategoryItems[3];
            Assert.True(item3.Id != Guid.Empty);
            Assert.Equal("milk-and-honey-parent", item3.WpNiceName);
            Assert.Equal("milk and honey parent", item3.Name);
            Assert.Equal("milk and honey parent", item3.Description);
        }

        [Fact]
        public void ParentCategory_ExpectParentCategory()
        {
            Category category = this.GetParsedCategory();
            Assert.True(category.CategoryItems[0].WpParentId == String.Empty); // finance
            Assert.True(String.IsNullOrEmpty(category.CategoryItems[0].ParentId));

            CategoryItem item5 = category.CategoryItems[5]; // honey
            Assert.Equal("honey", item5.Name);
            Assert.Equal("milk and honey parent", item5.WpParentId);
            Assert.True(item5.ParentId.Length > 0);
        }

        private Category GetParsedCategory()
        {
            Category category = new Category();
            XElement xElement = XElement.Load(WP_EXPORT_XML_FILE_NAME);
            category.Parse(xElement);
            
            return category;
        }
 
    }
}
